<template>
  <div>
    <TopFilter :labelWidth="90" :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :isSelectColumn="false"
      :isToperInfo="false"
      :onColumnsChange="columns => (this.columns = columns)"
      columnsRef="zjwxlsrepairProjectTable"
    ></FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer()">返 回</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { getSfqfSelect } from '@/api/repair/repairReception/customer';

import { getmaintainProjectList, getfindAllRepairType, getlendStuffQueryType } from '@/api/repair/business/customer/history';
import { getDealerUser } from '@/api/customerRepair/customerComplaint/customerComplaintReception';

export default {
  mixins: [dictionary],
  props: ['setdata'],
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createTopFilterList(),
      columns: this.createTable(),
      fetchApi: getmaintainProjectList,
      fetchParams: { vin: this.setdata.VIN, xhrAbort: true }
    };
  },
  created() {},
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    this.getEmp();
    this.getRepairType();
    this.getSfqfSelect();
    this.changeHandle();
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '项目代码',
          fieldName: 'labourCode'
        },
        {
          type: 'INPUT',
          label: '项目名称',
          fieldName: 'labourName'
        },
        {
          type: 'SELECT',
          label: '维修类型',
          placeholder: '请选择',
          fieldName: 'repairTypeCode',
          itemList: []
        },
        {
          type: 'INPUT',
          label: '进厂起始里程',
          fieldName: 'inMileageFrom'
        },
        {
          type: 'INPUT',
          label: '进厂结束里程',
          fieldName: 'inMileageTo'
        }
      ];
    },
    createTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '工单号',
          dataIndex: 'RO_NO',
          sorter: true,
          filter: true,
          filterType: 'input',
            showOverflowTooltip: true,
          render: props => {
            return <span>{props.row.RO_NO}</span>;
          }
        },
        {
          title: '项目代码',
          dataIndex: 'LABOUR_CODE',
          sorter: true,
          filter: true,
          filterType: 'input',
            showOverflowTooltip: true,
          render: props => {
            return <span>{props.row.LABOUR_CODE}</span>;
          }
        },
        {
          title: '项目名称',
          dataIndex: 'LABOUR_NAME',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true,
          render: props => {
            return <span>{props.row.LABOUR_NAME}</span>;
          }
        },
        {
          title: '项目维修类型',
          dataIndex: 'REPAIR_TYPE_CODE',
          sorter: true,
          filter: true,
          filterType: 'input',
            showOverflowTooltip: true,
        },
        {
          title: '进厂里程',
          dataIndex: 'IN_MILEAGE',
          sorter: true,
          filter: true,
          filterType: 'number',
            showOverflowTooltip: true,
          render: props => {
            return <span>{props.row.IN_MILEAGE}</span>;
          }
        },
        /* {
          title: '收费类别',
          dataIndex: 'MANAGE_SORT_CODE',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{props.row.MANAGE_SORT_CODE}</span>;
          }
        },*/
        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_CODE',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: false,
          editType: 'select',
          editItems: [],
        },
        {
          title: '检查结果',
          dataIndex: 'TROUBLE_DESC',
          sorter: true,
          filter: true,
          filterType: 'input',
            showOverflowTooltip: true,
          render: props => {
            return <span>{props.row.TROUBLE_DESC}</span>;
          }
        },
        {
          title: '故障原因',
          dataIndex: 'TROUBLE_CAUSE',
          sorter: true,
          filter: true,
          filterType: 'input',
            showOverflowTooltip: true,
          render: props => {
            return <span>{props.row.TROUBLE_CAUSE}</span>;
          }
        },
        {
          title: '标准工时',
          dataIndex: 'STD_LABOUR_HOUR',
          sorter: true,
          filter: true,
          filterType: 'number',
            showOverflowTooltip: true,
          render: props => {
            return <span>{props.row.STD_LABOUR_HOUR}</span>;
          }
        },
        {
          title: '派工工时',
          dataIndex: 'ASSIGN_LABOUR_HOUR',
          sorter: true,
          filter: true,
          filterType: 'input',
            showOverflowTooltip: true,
          render: props => {
            return <span>{props.row.ASSIGN_LABOUR_HOUR}</span>;
          }
        },
        {
          title: '工时单价',
          dataIndex: 'LABOUR_PRICE',
          sorter: true,
          filter: true,
          filterType: 'number',
            showOverflowTooltip: true,
          render: props => {
            return <span>{props.row.LABOUR_PRICE}</span>;
          }
        },
        {
          title: '折扣率',
          dataIndex: 'DISCOUNT',
          sorter: true,
          filter: true,
          filterType: 'number',
            showOverflowTooltip: true,
          render: props => {
            return <span>{props.row.DISCOUNT}</span>;
          }
        },

        {
          title: '工时费',
          dataIndex: 'LABOUR_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'number',
            showOverflowTooltip: true,
          render: props => {
            return <span>{props.row.LABOUR_AMOUNT}</span>;
          }
        },
        {
          title: '工种',
          dataIndex: 'WORKER_TYPE_CODE',
          sorter: true,
          filter: true,
          filterType: 'radio',
            showOverflowTooltip: true,
            filterItems: this.createDictList(8041),
          render: props => {
            return <span>{this.createDictText(props.row.ASSIGN_TAG, '8041')}</span>;
          }
        },
        {
          title: '派工标志',
          dataIndex: 'ASSIGN_TAG',
          sorter: true,
          filter: true,
          filterType: 'radio',
            showOverflowTooltip: true,
            filterItems: this.createDictList(1278),
          render: props => {
            return <span>{this.createDictText(props.row.ASSIGN_TAG, '1278')}</span>;
          }
        },
        {
          title: '责任技师',
          dataIndex: 'TECHNICIAN',
          sorter: true,
          filter: true,
          filterType: 'input',
          editType: 'select',
          editable: false,
          editItems: []
        },
        {
          title: '是否预检',
          dataIndex: 'PRE_CHECK',
          sorter: true,
          filter: true,
          filterType: 'radio',
            showOverflowTooltip: true,
            filterItems: this.createDictList(1004),
          render: props => {
            return <span>{this.createDictText(props.row.PRE_CHECK, '1004')}</span>;
          }
        },
        {
          title: '是否不修',
          dataIndex: 'NEEDLESS_REPAIR',
          sorter: true,
          filter: true,
          filterType: 'radio',
            showOverflowTooltip: true,
            filterItems: this.createDictList(1004),
          render: props => {
            return <span>{this.createDictText(props.row.NEEDLESS_REPAIR, '1004')}</span>;
          }
        },
        {
          title: '是否委外',
          dataIndex: 'CONSIGN_EXTERIOR',
          sorter: true,
          filter: true,
          filterType: 'radio',
            showOverflowTooltip: true,
            filterItems: this.createDictList(1004),
          render: props => {
            return <span>{this.createDictText(props.row.CONSIGN_EXTERIOR, '1004')}</span>;
          }
        },
        {
          title: '是否内返',
          dataIndex: 'INTER_RETURN',
          sorter: true,
          filter: true,
          filterType: 'radio',
            showOverflowTooltip: true,
            filterItems: this.createDictList(1004),
          render: props => {
            return <span>{this.createDictText(props.row.INTER_RETURN, '1004')}</span>;
          }
        },
        {
          title: '活动编号',
          dataIndex: 'ACTIVITY_CODE',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <span>{props.row.ACTIVITY_CODE}</span>;
          }
        },
        {
          title: '备注',
          dataIndex: 'REMARK',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <span>{props.row.REMARK}</span>;
          }
        }
      ];
    },
    // 搜索
    changeHandle(val) {
      if(!this.setdata.VIN){
        this.$notify.warning({ title: '提示信息', message: '请输入VIN' });
      }else{
        this.fetchParams = Object.assign({}, val, { xhrAbort: false, vin: this.setdata.VIN });
      }
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    // 获取维修类型
    async getRepairType() {
      const res = await getfindAllRepairType();
      let list = res.data.map(x => ({ text: x.REPAIR_TYPE_NAME, value: x.REPAIR_TYPE_CODE + '' }));

      this.topFilterList.find(item => item.fieldName === 'repairTypeCode').itemList = list; // 维修类型
    },
    // 获取全部员工
    async getEmp() {
      const res = await getDealerUser();
      let empList = res.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
      this.columns.find(item => item.dataIndex === 'TECHNICIAN').editItems = empList; // 责任技师
    },
    closeDrawer() {
      this.$emit('close', false);
    },
    async getSfqfSelect() {
      const res = await getSfqfSelect();
      this.columns.find(x => x.dataIndex === 'CHARGE_PARTITION_CODE').editItems = this.columns.find(x => x.dataIndex === 'CHARGE_PARTITION_CODE').filterItems = res.data.map(x => ({
        text: x.CHARGE_PARTITION_NAME,
        value: x.CHARGE_PARTITION_CODE
      }));
    }
  }
};
</script>
